package com.qb.plugin;

import com.android.build.gradle.internal.LoggerWrapper;

import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.LocalVariablesSorter;

import proguard.classfile.attribute.visitor.LocalVariableInfoVisitor;

/**
 * File: null.java
 * Creator: dingpwen
 * Company: shiwei
 * Created on: 2021/7/2 15:52
 * Email: dingpwen@gmail.com
 * Details: TODO
 */
class CommonMethodVisitor extends MethodVisitor implements Opcodes {
    private int lineNumber;
    private static final LoggerWrapper logger = LoggerWrapper.getLogger(CommonMethodVisitor.class);

    public CommonMethodVisitor(MethodVisitor methodVisitor) {
        super(Opcodes.ASM7, methodVisitor);
    }

    @Override
    public void visitLineNumber(int line, Label start) {
        this.lineNumber = line;
        super.visitLineNumber(line, start);
    }

    @Override
    public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
        //super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
        //logger.warning(opcode + " " + name);
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream");
        mv.visitLdcInsn("Call " + name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
        mv.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream");
        mv.visitLdcInsn("Return " + name);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
    }
}
